import { request } from '@/utils/request.js';
import { wechatLogin } from '@/utils/authUtils.js';
export default {
  data() {
    return {
      amount: '',
      peopleNum: 0,
      salary: 0
    };
  },

  onLoad(options) {
    // 接收从发布页面传递的参数
    this.amount = options.totalAmount;
    this.peopleNum = options.peopleNum;
    this.salary = options.salary;
    wechatLogin().then(res => {
      console.log('登录成功:', res);
    })
  },
  methods: {
    requestPayment() {
      if (!this.amount) {
        uni.showToast({
          title: '请输入支付金额',
          icon: 'none'
        });
        return;
      }

      // 模拟调用后端接口获取微信支付参数
      // 实际使用时需要替换为真实的后端接口地址
      request({
        url: 'Payment/test_pay',
        method: 'POST',
        data: {
          amount: this.amount
        },
        success: (res) => {
          if (res.data.code === 200) {
            const paymentParams = res.data.data;
            uni.requestPayment({
              ...paymentParams,
              success: () => {
                uni.showToast({
                  title: '支付成功',
                  icon: 'success'
                });
              },
              fail: (err) => {
                uni.showToast({
                  title: '支付失败',
                  icon: 'none'
                });
                console.error('支付失败:', err);
              }
            });
          } else {
            uni.showToast({
              title: res.data.message || '获取支付参数失败',
              icon: 'none'
            });
          }
        },
        fail: (err) => {
          uni.showToast({
            title: '请求支付参数失败',
            icon: 'none'
          });
          console.error('请求支付参数失败:', err);
        }
      });
    }
  }
};